﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
///PageHandlerBase 的摘要说明
/// </summary>
public class PageHandlerBase : IHttpHandler
{
	#region Private Variables
    private string strSessionKey;
    private static readonly string HiddenFieldName = "__LastVIEWSTATE_SessionKey";
    private string strLastViewstate;
    private bool _err = false;
    protected StateManager mTheSession = new StateManager();
    private static object _SecurityValidPass = new object();
    protected string AlertType = "Default";
    public static string Ver;
    #endregion
   public StateManager MyStateManager
    {
        get { return mTheSession; }
    }

    public Boolean ReadOnly
    {
        get;
        set;
    }

    private bool UserRight(string Link)
    {
        return true;
        //string temp = RoleManager.GetOtherRights(MyStateManager.UserID);
        //int t = temp.IndexOf(Link.ToUpper());
        //int b = MyStateManager.Rights.IndexOf(Link.ToUpper());
        //if (MyStateManager.Rights.IndexOf(Link.ToUpper()) > -1)//在权限中
        //{
        //    return true;
        //}
        //else if (!(temp.IndexOf(Link.ToUpper()) > -1))
        //{
        //    return true;
        //}
        //return false;


    }

    protected string MessageType(bool url)
    {
        if (AlertType == "Default")
        {
            return "alert(\"{0}\");";
        }
        else if (AlertType == "EasyUI")
        {
            return url ? ("$.messager.alert('提示消息','{0}', 'info'{1});") : ("$.messager.alert('提示消息','{0}', 'info');");
        }
        else
        {
            return "alert(\"{0}\");";
        }
    }

   
 #region Public Property

 
   
    public bool IsRefreshed
    {
        get
        {
            //string str1 = this.Request.Form["__VIEWSTATE"];
            //strLastViewstate = str1;
            //string str2 = this.Session[GetSessinKey()] as string;
            //bool flag1 = (str1 != null) && (str2 != null) && (str1 == str2);
            //return flag1;

            return false;
        }
    }
    #endregion

  

    /// <summary>
    /// 显示消息提示对话框，并进行页面跳转
    /// </summary>
    /// <param name="page">当前页面指针，一般为this</param>
    /// <param name="msg">提示信息</param>
    /// <param name="url">跳转的目标URL</param>
    public void ShowAndRedirect(System.Web.UI.Page page, string msg, string url)
    {
        System.Text.StringBuilder Builder = new System.Text.StringBuilder();
        Builder.Append("<script language='javascript' defer>");
        if (AlertType == "EasyUI")
        {
            Builder.AppendFormat(MessageType(true), msg.Replace("\"", "'"), ",function() { parent.location.href='" + url + "'; }");
        }
        else
        {
            Builder.AppendFormat(MessageType(false), msg.Replace("\"", "'"));
            Builder.AppendFormat("parent.location.href='{0}'", url);
        }
        Builder.Append("</script>");
        page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());

    }



    public virtual void ProcessRequest(HttpContext context)
    {
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}